import QtQuick
import QtQuick.Window

Rectangle {
    Rectangle {
        id: square
        width: 100; height: 100
        color: 'green'
        border.color: Qt.lighter(color) // 现有颜色基础上浅一点
    }

    focus: true
    Keys.onLeftPressed: square.x -= 8
    Keys.onRightPressed: square.x += 8
    Keys.onUpPressed: square.y -= 8
    Keys.onDownPressed: square.y += 8
    Keys.onPressed: function(event) { // 处理按键
        switch(event.key) {
        case Qt.Key_Plus:
            square.scale += 0.2
            break
        case Qt.Key_Minus:
            if (square.scale > 0.2) square.scale -= 0.2
            else square.scale = 0
            break
        }
    }

}
